package com.ebupt.migu.music.statistics.service.impl;

import com.ebupt.migu.music.statistics.entity.PushResult;
import com.ebupt.migu.music.statistics.entity.StatisticsPush;
import com.ebupt.migu.music.statistics.mapper.StatisticsPushTaskMapper;
import com.ebupt.migu.music.statistics.service.StatisticsPushTaskService;
import com.ebupt.migu.music.strategy.entity.StrategyInfo;
import com.ebupt.migu.music.userGroup.entity.UserGroupInfo;
import com.ebupt.migu.music.userGroup.mapper.CrowdMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Intellij IDEA.
 * User:  liuyangyang@cd.ebupt.com
 * Date:  2019/9/24
 */
@Slf4j
@Service
public class StatisticsPushTaskServiceImpl implements StatisticsPushTaskService {

    @Autowired
    private StatisticsPushTaskMapper sptMapper;
    @Autowired
    private CrowdMapper crowdMapper;

    @Override
    public List<StrategyInfo> queryStrategyPushList() {
        return sptMapper.queryStrategyPushList();
    }

    @Override
    public int createStatisPush(Map<String, Object> params) {
        return sptMapper.createStatisPush(params);
    }

    @Override
    public StatisticsPush queryStatisticsPush(String strategyId) {
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("strategyId",strategyId);
        List<StatisticsPush> list= sptMapper.queryStatisticsPush(paramMap);
        if(null!=list&&list.size()>0){
            return list.get(0);
        }
         return null;
    }

    @Override
    public int updateStatisPush(Map<String, Object> paramMap) {
        return sptMapper.updateStatisPush(paramMap);
    }

    @Override
    public UserGroupInfo queryByGroupId(String groupId) {
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("groupId",groupId);
        List<UserGroupInfo> list= sptMapper.queryByGroupId(paramMap);
        if(null!=list&&list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<PushResult> queryPushResultList() {
        return sptMapper.queryPushResultList();
    }

    @Override
    public StrategyInfo queryByStrategyId(String strategyId) {
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("strategyId",strategyId);
        List<StrategyInfo> list= sptMapper.queryByStrategyId(paramMap);
        if(null!=list&&list.size()>0){
            return list.get(0);
        }
        return null;
    }

    @Override
    public int updatePushResultStatus(String strategyId,String pushDate) {
        Map<String, Object> paramMap=new HashMap<String, Object>();
        paramMap.put("strategyId",strategyId);
        paramMap.put("pushDate",pushDate);
        return sptMapper.updatePushResultStatus(paramMap);
    }


    /**
     *   判断是否存在task id
     * @param taskId
     * @return
     */
    @Override
    public Boolean IsHaveTaskId(String taskId){
        return sptMapper.selectByTaskId(taskId)==0?false:true;
    }

    @Override
    public List<PushResult> queryPushResultList(String pushDate) {
        return sptMapper.queryPushResultListByPushDate(pushDate);
    }
}